from django.contrib import admin
from .models.wechat_user import WechatUser
from .models.audio import Audio
from .models.vip import VipActivationCode, VipMember

@admin.register(VipActivationCode)
class VipActivationCodeAdmin(admin.ModelAdmin):
    list_display = ('code', 'vip_type', 'is_used', 'used_by', 'used_at', 'created_at')
    list_filter = ('vip_type', 'is_used')
    search_fields = ('code', 'used_by__nickname')
    readonly_fields = ('code', 'created_at')
    ordering = ('-created_at',)

    def get_readonly_fields(self, request, obj=None):
        if obj:  # 编辑现有对象时
            return self.readonly_fields + ('vip_type',)
        return self.readonly_fields

@admin.register(VipMember)
class VipMemberAdmin(admin.ModelAdmin):
    list_display = ('user', 'vip_type', 'start_time', 'end_time', 'is_active')
    list_filter = ('vip_type', 'is_active')
    search_fields = ('user__nickname',)
    readonly_fields = ('created_at', 'updated_at')
    ordering = ('-created_at',)

    def get_readonly_fields(self, request, obj=None):
        if obj:  # 编辑现有对象时
            return self.readonly_fields + ('user',)
        return self.readonly_fields
